public class JumpSolution {
    public static void main(String[] args) {
        JumpSolution jumpSolution =new JumpSolution();
        int[] nums ={2,3,1,1,4};
        int jump = jumpSolution.jump(nums);
        System.out.println(jump);
    }
    public int jump(int[] nums) {
        //逆向遍历数组，找到最远能够达到的位置
        //题目默认是能达到最后一位
        int distIndex = nums.length-1;
        int count = 0;
        while(distIndex !=0){
            int minIndex = distIndex;
            count++;
            for(int i= distIndex-1;i>=0;i--){
                if(nums[i]+i>=distIndex){
                    minIndex = Math.min(minIndex,i);
                }
            }
            distIndex = minIndex;
        }
        return count;
    }
}
